/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view.GUI;

import dao.Cliente.ClienteDao;
import dao.Cliente.ClienteDaoImpl;
import dao.Fornecedor.FornecedorDao;
import dao.Fornecedor.FornecedorDaoImpl;
import dao.Item.ItemDao;
import dao.Item.ItemDaoImpl;
import dao.NotaFiscal.NotaFiscalDao;
import dao.NotaFiscal.NotaFiscalDaoImpl;
import dao.Pedido.PedidoDao;
import dao.Pedido.PedidoDaoImpl;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author lg
 */
public class GUIPrincipal extends javax.swing.JFrame {

    private final ItemDao item;
    private final ClienteDao cliente;
    private final FornecedorDao fornecedor;
    private final NotaFiscalDao notaFiscal;
    private final PedidoDao pedido;
    private Image img;

    /**
     * Creates new form GUIPrincipal2
     */
    
    public GUIPrincipal() {
        //this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        GUIPrincipal.this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                //caixa de dialogo retorna um inteiro  
                int resposta = JOptionPane.showConfirmDialog(null, "Deseja finalizar o programa?", "Finalizar", JOptionPane.YES_NO_OPTION);

                //sim = 0, nao = 1  
                if (resposta == 0) {
//                    item.salvarDisco();
//                    fornecedor.salvarDisco();
//                    cliente.salvarDisco();
//                    notaFiscal.salvarDisco();
//                    pedido.salvarDisco();
                    System.exit(0);
                }
                    
            }
        });
        initComponents();
        this.setTitle("SM Confecções");
        boolean carregarDisco;
        item = new ItemDaoImpl();
        cliente = new ClienteDaoImpl();
        fornecedor = new FornecedorDaoImpl();
        notaFiscal = new NotaFiscalDaoImpl();
        pedido = new PedidoDaoImpl();

//        //Carregando arquivos.
//        carregarDisco = fornecedor.carregarDisco();
//        if (carregarDisco == false) {
//            System.out.println("Problema ao ler arquivo de fornecedores.");
//        }
//        carregarDisco = item.carregarDisco();
//        if (carregarDisco == false) {
//            System.out.println("Problema ao ler arquivo de itens.");
//        }
//        carregarDisco = cliente.carregarDisco();
//        if (carregarDisco == false) {
//            System.out.println("Problema ao ler arquivo de clientes.");
//        }
//        carregarDisco = pedido.carregarDisco(item);
//        if (carregarDisco == false) {
//            System.out.println("Problema ao ler arquivo de pedidos.");
//        }
//
//        carregarDisco = notaFiscal.carregarDisco();
//        if (carregarDisco == false) {
//            System.out.println("Problema ao ler arquivo de notaFiscal.");
//        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jDesktopPane1 = new util.backGround();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(1024, 600));

        jPanel3.setBackground(new java.awt.Color(254, 254, 254));

        jButton1.setText("Compras");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Vendas");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Cadastrar Cliente");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Consultar Itens");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton6.setText("Listar Clientes");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("Listar Fornecedores");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("Pedidos em Aberto");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton11.setText("Cadastrar Fornecedor");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jButton5.setText("Fechar Pedido");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE))
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton5)
                .addContainerGap(90, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jDesktopPane1)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        GUICompras compras = new GUICompras(this.fornecedor,this.jDesktopPane1,(ItemDaoImpl) item);
        compras.setTitle("Compras");
        compras.setVisible(true);
        compras.setResizable(true);
        compras.setMaximizable(true);
        compras.setClosable(false);
        compras.setIconifiable(true);
        compras.setVisible(true);
        this.jDesktopPane1.add(compras);
        compras.moveToFront();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        GUICadastroCliente cadastroCliente = new GUICadastroCliente((ClienteDaoImpl) this.cliente);
        cadastroCliente.setTitle("Cadastro de Clientes");
        cadastroCliente.setVisible(true);
        cadastroCliente.setResizable(true);
        cadastroCliente.setMaximizable(true);
        cadastroCliente.setClosable(true);
        cadastroCliente.setIconifiable(true);
        cadastroCliente.setVisible(true);
        cadastroCliente.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.jDesktopPane1.add(cadastroCliente);
        cadastroCliente.moveToFront();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        GUIConsultarItens consultaItens = new GUIConsultarItens(item);
        consultaItens.setTitle("Consulta de itens");
        consultaItens.setVisible(true);
        consultaItens.setResizable(true);
        consultaItens.setMaximizable(true);
        consultaItens.setClosable(true);
        consultaItens.setIconifiable(true);
        consultaItens.setVisible(true);
        consultaItens.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.jDesktopPane1.add(consultaItens);
        consultaItens.moveToFront();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        GUIListarFornecedores listarFornecedores = new GUIListarFornecedores((FornecedorDaoImpl) fornecedor);
        listarFornecedores.setTitle("Listar Fornecedores");
        listarFornecedores.setVisible(true);
        listarFornecedores.setResizable(true);
        listarFornecedores.setMaximizable(true);
        listarFornecedores.setClosable(true);
        listarFornecedores.setIconifiable(true);
        listarFornecedores.setVisible(true);
        listarFornecedores.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.jDesktopPane1.add(listarFornecedores);
        listarFornecedores.moveToFront();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        GUIListarClientes listarClientes = new GUIListarClientes((ClienteDao) cliente);
        listarClientes.setTitle("Listar Clientes");
        listarClientes.setVisible(true);
        listarClientes.setResizable(true);
        listarClientes.setMaximizable(true);
        listarClientes.setClosable(true);
        listarClientes.setIconifiable(true);
        listarClientes.setVisible(true);
        listarClientes.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.jDesktopPane1.add(listarClientes);
        listarClientes.moveToFront();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        GUICadastroFornecedor cadastroFornecedor = new GUICadastroFornecedor(fornecedor);
        cadastroFornecedor.setTitle("Cadastrar Fornecedores");
        cadastroFornecedor.setVisible(true);
        cadastroFornecedor.setResizable(true);
        cadastroFornecedor.setMaximizable(true);
        cadastroFornecedor.setClosable(true);
        cadastroFornecedor.setIconifiable(true);
        cadastroFornecedor.setVisible(true);
        cadastroFornecedor.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.jDesktopPane1.add(cadastroFornecedor);
        cadastroFornecedor.moveToFront();
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        GUIVendas vendas = new GUIVendas(item,cliente,pedido,this.jDesktopPane1,notaFiscal);
        vendas.setTitle("Vendas");
        vendas.setVisible(true);
        vendas.setResizable(true);
        vendas.setMaximizable(true);
        vendas.setClosable(false);
        vendas.setIconifiable(true);
        vendas.setVisible(true);
        vendas.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.jDesktopPane1.add(vendas);
        vendas.moveToFront();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        GUIPedidos pedidos = new GUIPedidos(cliente, jDesktopPane1,item,pedido,notaFiscal);
        pedidos.setTitle("Pedidos em aberto");
        pedidos.setVisible(true);
        pedidos.setResizable(true);
        pedidos.setMaximizable(true);
        pedidos.setClosable(true);
        pedidos.setIconifiable(true);
        pedidos.setVisible(true);
        pedidos.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.jDesktopPane1.add(pedidos);
        pedidos.moveToFront();
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        GUIPedidos pedidos = new GUIPedidos(cliente, jDesktopPane1,item,pedido,notaFiscal);
        pedidos.setTitle("Escolha de pedido para fechamento");
        pedidos.setVisible(true);
        pedidos.setResizable(true);
        pedidos.setMaximizable(true);
        pedidos.setClosable(true);
        pedidos.setIconifiable(true);
        pedidos.setVisible(true);
        pedidos.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.jDesktopPane1.add(pedidos);
        pedidos.moveToFront();
    }//GEN-LAST:event_jButton5ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUIPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUIPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUIPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUIPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {

                GUIPrincipal principal = new GUIPrincipal();

                principal.setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JPanel jPanel3;
    // End of variables declaration//GEN-END:variables
}
